package com.example.tvwanandroid.presenter

import com.example.tvwanandroid.base.BaseObserver
import com.example.tvwanandroid.base.BasePresenter
import com.example.tvwanandroid.base.BaseResult
import com.example.tvwanandroid.bean.ArticleListBean
import com.example.tvwanandroid.bean.BaseCodeBean
import com.example.tvwanandroid.bean.CodeBean
import com.example.tvwanandroid.view.ArticleListView
import okhttp3.RequestBody

/**
 * @作者: njb
 * @时间: 2020/12/3 17:48
 * @描述:
 */
class HomePresenter(baseView: ArticleListView) : BasePresenter<ArticleListView>(baseView) {
    /**
     * 文章列表
     */
    fun articleList( page: Int) {
        addDisposable(apiServer.articleList(page),object :BaseObserver<BaseResult<ArticleListBean>>(baseView){
            override fun onSuccess(o: BaseResult<ArticleListBean>) {
                baseView!!.onLoadArtList(o.data!!)
            }

            override fun onError(msg: String?) {
                baseView!!.showError(msg!!)
            }

        })

    }

    fun getSendCode(body: CodeBean){
        addDisposable(apiServer.getSendCode(body),object :BaseObserver<BaseCodeBean<Any>>(baseView){
            override fun onSuccess(o: BaseCodeBean<Any>) {
                baseView.onLoadSendCode(o)
            }

            override fun onError(msg: String?) {
                baseView.showError(msg!!)
            }

        })
    }
}